<?php 


require "../common/Curl.php";

/**
 *	https=>//open.esign.cn/doc/detail?id=opendoc%2Fpaas_api%2Fsgv49u&namespace=opendoc%2Fpaas_api
 * 	电子签名SaaS API非标版
 * 	流程附件----接口顺序排列封装
 *  使用请求签名鉴权方式
 *  下一个------------------ 流程签署区 sign4.php
 */



//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


/**
 * [createProcessAttachment 流程附件添加]
 * @param  [type] $aaaa   [description]
 * @param  [type] $flowId [description]
 * @param  [type] $appId  [description]
 * @param  [type] $secret [description]
 * @param  [type] $url    [description]
 * @return [type]         [description]
 */
function createProcessAttachment($aaaa,$flowId,$appId,$secret,$url){
	$urlss = $url."/v1/signflows/".$flowId."/attachments";
	$head_url = "/v1/signflows/".$flowId."/attachments";
    $data = json_decode($aaaa,true);
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $aaaa = '{
//     "attachments":[
//         {
//             "attachmentName":"第一份附件.pdf",
//             "fileId":"97913b341a0142e08aef061c6ccae5da"
//         }
//     ]
// }';
// $a = createProcessAttachment($aaaa,$flowId,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [selectProcessAttachment 流程附件列表]
 * @param  [type] $flowId [description]
 * @param  [type] $appId  [description]
 * @param  [type] $secret [description]
 * @param  [type] $url    [description]
 * @return [type]         [description]
 */
function selectProcessAttachment($flowId,$appId,$secret,$url){
	$urlss = $url."/v1/signflows/".$flowId."/attachments";
	$head_url = "/v1/signflows/".$flowId."/attachments";
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"GET",$head_url,$appId,$secret);
    $result = sendHttp($method="GET",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $a = selectProcessAttachment($flowId,$appId,$secret,$url);
// var_dump($a);die;


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [deleteProcessAttachment 流程附件删除]
 * @param  [type] $flowId  [description]
 * @param  [type] $fileIds [description]
 * @param  [type] $appId   [description]
 * @param  [type] $secret  [description]
 * @param  [type] $url     [description]
 * @return [type]          [description]
 */
function deleteProcessAttachment($flowId,$fileIds,$appId,$secret,$url){
	$file = '';
	foreach ($fileIds as $key => $value) {
		$file = $file.",".$value;   // 连接数组
	}
	$file = substr($file,1);  // 去除第一个，逗号
	$urlss = $url."/v1/signflows/".$flowId."/documents?fileIds=".$file;
	$head_url = "/v1/signflows/".$flowId."/documents?fileIds=".$file;
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"DELETE",$head_url,$appId,$secret);
    $result = sendHttp($method="DELETE",$urlss,$header,$res);
    return $result;
}
// $flowId = "9a1f67f7f8094d5bbe24ff6927ba4e03";
// $fileIds = array('01e50a9cedb74493a2d320b4f4732a29','ee2da3b8cc60422e8076ec55489fb0da');
// $a = deleteProcessAttachment($flowId,$fileIds,$appId,$secret,$url);
// var_dump($a);die;








